package Lono::Fetcher::Response;

use warnings;
use strict;

=head1 NAME

Lono::Fetcher::Response - encapsulates a response from different fetchers.

=head1 SYNOPSIS

  my $resp = Lono::Fetcher::Response->new;

  $resp->log->warning( 'Difficulty doing something.' );
  $resp->set_recipe( $recipe );

  my $status = $resp->get_status;

=head1 DESCRIPTION

This class encapsulates a response from a Lono::Fetcher::Client::* class.

=cut

use Lono::Util::Logger;


our $SUCCESS = 'SUCCESS';
our $COMPLETED_WITH_WARNINGS = 'COMPLETED_WITH_ERRORS';
our $PARSING_ERROR = 'PARSING_ERROR';
our $FETCHING_ERROR = 'FETCHING_ERROR';

=head1 FUNCTIONS

=over 4

=item new()

A new instance.

=cut

sub new {
    my $class = shift;
    # Initial status 
    my $self = {'_status' => $FETCHING_ERROR,
                '_log' => Lono::Util::Logger->new};
    bless $self, $class;
    return $self;
}

=item set_recipe( $recipe )

Set the recipe object for the response.

=cut

sub set_recipe {
    my ($self, $recipe) = @_;
    $self->{'recipe'} = $recipe;
}

=item get_recipe()

Returns the recipe.

=cut

sub get_recipe {
    my ($self) = @_;
    return $self->{'recipe'};
}

=item set_status( STATUS )

Set the status for the response.

=cut

sub set_status {
    my ($self, $status) = @_;
    $self->{'_status'} = $status;
}

=item get_status()

Returns the status.

=cut

sub get_status {
    my ($self) = @_;
    return $self->{'_status'};
}

=item is_success()

Returns whether or not the response is successful.

=cut

sub is_success {
    my ($self) = @_;
    return $self->{'_status'} eq $SUCCESS;
}

=item log()

Retrieves the log object, an instance of Lono::Util::Logging.

=cut

sub log {
    my $self = shift;
    return $self->{'_log'};
}

=back 4

=cut

1;
